package com.tmsps.ne4Weixin.api;

import com.alibaba.fastjson.JSON;
import com.tmsps.ne4Weixin.api.entity.template.TemplateMsg;
import com.tmsps.ne4Weixin.beans.TemplateBackInfo;
import com.tmsps.ne4Weixin.config.WxConfig;
import com.tmsps.ne4Weixin.utils.HttpClient;

public class TemplateMsgAPI extends BaseAPI {

	private static final String TemplateSendURL = BaseURL.concat("/cgi-bin/message/template/send?access_token=%s");

	public TemplateMsgAPI(WxConfig config) {
		super(config);
	}

	public TemplateBackInfo send(TemplateMsg template) {
		log.debug(template.toJson());
		String result = HttpClient.postJson(String.format(TemplateSendURL, config.getAccessToken()), template.toJson());
		return JSON.parseObject(result, TemplateBackInfo.class);
	}
}
